﻿using System;
using System.Threading.Tasks;

using Jack.RedisEventBus.WebApiDemo.EventBus;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Jack.RedisEventBus.WebApiDemo.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderEventController : ControllerBase
    {
        [HttpGet]
        public async Task<IActionResult> SendEvent([FromServices]IEventPublisher eventPublisher)
        {
            OrderEvent orderEvent = new OrderEvent { OrderNo = Guid.NewGuid().ToString() };
            await eventPublisher.Publish(orderEvent);
            return Ok(orderEvent);
        }
    }
}
